package Books.Example;

/* 字符串的基本数据类型相互转化：
 * 	1、字符串转化为"数字"，byte, short, int, long, float, double
 * 		public static int parseInt(String s) // java.lang.Integer
 * 		public static byte parseByte(String s); // java.lang.Byte
 * 		public static short parseShort(String s); // java.lang.Short
 * 		public static long parseLong(String s); //
 * 		public static float parseFloat(String s)
 * 		public static double parseDouble(String s);
 * 			Examples:
 * 				int x;
 * 				String s = "867";
 * 				x = Integer.parseInt(s);
 * 
 *  2、"数字"转化为字符串:
 *  	public static String valueOf(byte n);
 *  	public static String valueOf(int n);
 *  	public static String valueOf(long n);
 *  	public static String valueOf(float n);
 *  	public static String valueOf(double n);
 *  		Examples:
 *  			String str = String.valueOf(123123.12312324);
 * */

public class Example8_4 {
	public static void main(String args[]) throws Exception {
		double sum = 0, item = 0;
		boolean computable = true;

        System.out.println(args.length);
		
		for(String s:args) {
			try {
				item = Double.parseDouble(s);
				sum += item;
			} catch (NumberFormatException e) {
				System.out.println("您输入的非数字字符:" + e);
				computable = false;
			}
		}
		
		if (computable) {
			System.out.println("sum = " + sum);
		}
	}
}
